/*
 * Plane.cpp
 *
 *  Created on: Jul 2, 2010
 *      Author: Ry
 */

#include "Plane.h"

Plane::Plane() {
	p = Vector3(0.0f, 0.0f, 0.0f);
	n = Vector3(0.0f, 0.0f, 0.0f);
}

bool Plane::intersection(const Ray &r, bool infinite, Vector3 &result) {
	float x = r.d * n;

	// Ray is parallel to the plane
	if (x == 0)
		return false;

	// Ray is not facing the plane
	if (x > 0) {
		return false;
	}

	float t = ((p * n) - r.p * n) / x;
	result = r.p + r.d * t;

	return infinite ? true : t < r.d.length();
}


Plane::~Plane() {
}
